﻿@{
    ViewBag.Title = "领料通知";
    Layout = "~/Views/Shared/FrameWorkList.cshtml";
}

<body>
    <div class="functionHeader" style="width:100%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:2px solid #CCC;">
        <div class="lsider">
            <div class="updowninput btn-group" style="margin-top:10px;">
                <input id="radio11" class="category" name="category" value="登记" checked="checked" type="radio"><label for="radio11" class="suffix">登记</label><br>
                <input id="radio12" class="category" name="category" value="档案" type="radio"><label for="radio12" class="suffix">档案</label>
            </div>
            <div class="updowninput" style="width:160px;height:20px;margin-left:10px;">
                <p>领料单位</p>
                <select id="txtFHappenCompanyNO" name="FHappenCompanyNO" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>零部件号</p>
                <input type="text" id="txtFDocuTypeNO" class="form-control required" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>供货单位</p>
                <select id="txtqueryFProCompanyNO" class="form-control">
                    <option value="">==请选择==</option>
                </select>
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>出库日期</p>
                <input id="txtqueryFCurDate" type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker()" />
                &nbsp;
            </div>
            <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
                <p>凭证编号</p>
                <input id="txtqueryFVoucherNo" type="text" class="form-control required" />
                &nbsp;
            </div>
            <div class="btn-group" style="margin-top:12px;margin-left:10px;">
                &nbsp;
                <a class="btn btn-primary center-block" id="btn_search"><span class="glyphicon glyphicon-search"></span>  &nbsp; 查询</a>
            </div>
        </div>

        <div class="rsider">
            <div class="btn-group btn-operration" style="float:right;margin-top:12px;">
                <a class="btn btn-primary center-block" onclick="$.reload()">  <span class="glyphicon glyphicon-refresh"></span>&nbsp刷新</a>
                <a class="btn btn-primary center-block active" onclick="btn_Add()">   <span class="glyphicon glyphicon-plus"></span>&nbsp输入</a>
                <a class="btn btn-primary center-block active" onclick="btn_Delete()"><span class="glyphicon glyphicon-trash"></span>&nbsp删除</a>
                <a class="btn btn-primary center-block active" onclick="btn_Save()">  <span class="glyphicon glyphicon-edit"></span>&nbsp备料</a>
                <a class="btn btn-primary center-block active" onclick="btn_operration_Edit()">  <span class="glyphicon glyphicon-edit"></span>&nbsp修改</a>
                <a class="btn btn-primary center-block" onclick="btn_Excel()"> <span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
            </div>
        </div>

        <div class="btn-group btn-edit-entity" style="float:left;margin-top:12px;display:none;">
            <a class="btn btn-primary center-block" onclick="btn_Edit();">   <span class="glyphicon ">    </span>修改</a>
            <a class="btn btn-primary center-block" onclick="btn_Cancel();"><span class="glyphicon ">   </span>关闭</a>
        </div>
    </div>
    <table id="eidt_entity" class="form" style="width:97%;display:none; text-align:left;margin:0px;margin-top:0px;margin-bottom:0px;">
        <tr>
            <th class="formTitle">领料日期</th>
            <td class="formValue" style="width:120px;">
                <input id="txtFCurDate" name="FCurDate" class="form-control" type="text">
            </td>
            <th class="formTitle">零件编号</th>
            <td class="formValue" style="width:140px;">
                <input id="txtFProductionNO" name="FProductionNO" class="form-control" readonly="readonly" type="text">
            </td>
            <th class="formTitle">开票数量</th>
            <td class="formValue" style="width:60px;">
                <input id="txtFQuantity_KP" name="FQuantity_KP" class="form-control decimal" readonly="readonly" type="text">
            </td>
            <th class="formTitle">容器编号</th>
            <td class="formValue">
                <input id="txtFContainerNO" name="FContainerNO" class="form-control" type="text">
            </td>
            <th class="formTitle">容器容量</th>
            <td class="formValue" style="width:80px;">
                <input id="txtFFactContent" name="FFactContent" class="form-control decimal suffix" style="width:36px;margin-left:2px;" type="text"><label class="suffix">件/箱</label>
            </td>
            <th class="formTitle">托盘编号</th>
            <td class="formValue">
                <input id="txtFPalletNO" name="FPalletNO" class="form-control" type="text">
            </td>
            <th class="formTitle">托盘容量</th>
            <td class="formValue" style="width:80px;">
                <input id="txtFPalletFactContent" name="FPalletFactContent" class="form-control decimal suffix" style="width:36px;margin-left:2px;" type="text"><label class="suffix">箱/托</label>
            </td>
            <th class="formTitle"></th>
            <td class="formValue"></td>
            <td></td>
        </tr>
        <tr>
            <th class="formTitle">领料单位</th>
            <td class="formValue">
                <input id="txtFProCompanyName" name="FProCompanyName" class="form-control" readonly="readonly" type="text">
            </td>
            <th class="formTitle">零件名称</th>
            <td class="formValue">
                <input id="txtFProductionName" name="FProductionName" class="form-control" readonly="readonly" type="text">
            </td>
            <th class="formTitle">实际数量</th>
            <td class="formValue">
                <input id="txtFQuantity" name="FQuantity" class="form-control decimal" type="text">
            </td>
            <th class="formTitle">容器名称</th>
            <td class="formValue">
                <input id="txtFContainerName" name="FContainerName" class="form-control" readonly="readonly" type="text">
            </td>
            <th class="formTitle">容器数量</th>
            <td class="formValue">
                <input id="txtFContainerQuantity" name="FContainerQuantity" class="form-control decimal suffix" style="width:36px;margin-left:2px;" type="text"><label class="suffix">箱</label>
            </td>
            <th class="formTitle">托盘名称</th>
            <td class="formValue">
                <input id="txtPalletName" name="PalletName" class="form-control" readonly="readonly" type="text">
            </td>
            <th class="formTitle">托盘数量</th>
            <td class="formValue">
                <input id="txtFPalletQuantity" name="FPalletQuantity" class="form-control decimal suffix" style="width:36px;margin-left:2px;" type="text"><label class="suffix">托</label>
            </td>
            <th class="formTitle">备注</th>
            <td class="formValue">
                <input id="txtFDescription" name="FDescription" class="form-control" type="text">
            </td>
        </tr>
    </table>
    <div id="gridReg">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <div id="gridArc">
        <table id="gridList2"></table>
        <div id="gridPager2"></div>
    </div>
</body>




<script>
    var rowData = {};
    var index = -1;
    $(function () {
        initControl();
        gridList1();
    });
    function initControl() {
        $('select').bindSelect();
        $('.category').on("click", function () {
            var aa = $("input[type='radio'].category:checked").val();
            if (aa == '登记') {
                gridList1();
            } else {
                gridList2();
            }
        });
        //领料单位
        $("#txtFHappenCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isCustomer=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //供货单位
        $("#txtqueryFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetProCompany?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName",
            search: true
        });
        //数据联动
        textChange();
    }

    function btn_Ok() {
        $.each(rowData, function (key, value) {
            rowData[key] = $("#txt" + key).val();
        });
        $("#gridList1").jqGrid('setRowData', index, rowData);
    }

    function btn_operration_Edit() {
        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
    }

    function btn_Edit() {
        $.each(rowData, function (key, value) {
            if ($("#txt" + key).val()) {
                rowData[key] = $("#txt" + key).val();
            }
        });
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/SaveDJ_StoRegister",
            param: rowData,
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        });
    }

    function btn_Cancel() {

        $.showOrHide($(".btn-operration"));
        $.showOrHide($("#eidt_entity"));
        $.showOrHide($(".btn-edit-entity"));
        $.each(rowData, function (key, value) {
            rowData[key] = "";
        });
    }
    //登记
    function showReg() {
        $("#gridReg").show();
        $("#gridArc").hide();
        $(".rsider .active").show();
    }
    //档案
    function showArc() {
        $("#gridReg").hide();
        $("#gridArc").show();
        $(".rsider .active").hide();
    }

    function btn_Save() {
        var postData = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            debugger
            postData.push($("#gridList1").jqGrid('getRowData', rowid));
        });
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/SavePrepare",
            param: { datas: JSON.stringify(postData) },
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function gridList1() {
        showReg();
        var $gridList = $("#gridList1");
        $gridList.dataGridForJson({
            url: "/VBaseData/V_CPK_11_DJ_StoRegister/GetGridJsonForPick",
            height: $(window).height() - 160,
            colModel: [
            { label: "id", name: "FRegisterID", width: 120, align: 'center', hidden: true },
            { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
            { label: "错误提示", name: "FERROR", width: 120, align: 'left'},
            { label: "领料单位", name: "FHappenCompanyNO", width: 120, align: 'left' },
            { label: "领料单位名称", name: "FHappenCompanyName", width: 120, align: 'left' },
            { label: '出库日期', name: 'FCurDate', width:100, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width: 140, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 160, align: 'left' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },

            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
            { label: '实际装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'left' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },

            { label: '实际容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '标准容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'left' },
            { label: '供货单位', name: 'FProCompanyNO', width: 80, align: 'left' },
           
            { label: '供货单位名称', name: 'FProCompanyName', width: 120, align: 'left' },
            { label: '零件分类', name: 'FProductionTypeNO', width: 80, align: 'left', hidden: true },
            { label: '零件分类名称', name: 'FProductionTypeName', width: 80, align: 'left' },
            
            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 80, align: 'center' },
            ],
            pager: "#gridPager1",
            sortname: 'FCurDate desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            },
            gridComplete: function () {
                $gridList.find('[title="库存不足"]').each(function () {
                    $(this).parent().css("color", "red");
                });
            }
        });
      
        $("#btn_search").click(function () {
            query($gridList);
        });
        $("#selectAll").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function gridList2() {
        showArc();
        var $gridList = $("#gridList2");
        $gridList.dataGrid({
            url: "/VBaseData/V_CPK_12_DJ_StoRegister_Mid/GetPickListJson",
            height: $(window).height() - 160,
            colModel: [
            { label: "领料单位", name: "FHappenCompanyNO", width: 120, align: 'left' },
            { label: "领料单位名称", name: "FHappenCompanyName", width: 120, align: 'left' },
            { label: '出库日期', name: 'FCurDate', width: 100, align: 'center' },
            { label: '零件编号', name: 'FProductionNO', width: 140, align: 'left' },
            { label: '零件名称', name: 'FProductionName', width: 160, align: 'left' },
            { label: '开票数量', name: 'FQuantity_KP', width: 80, align: 'right' },
            { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },

            { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
            { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
            { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
            { label: '实际装箱', name: 'FContent', width: 80, align: 'right' },
            { label: '标准装箱', name: 'FFactContent', width: 80, align: 'right' },
            { label: '托盘编号', name: 'FPalletNO', width: 80, align: 'left' },
            { label: '托盘数量', name: 'FPalletQuantity', width: 80, align: 'right' },

            { label: '实际容量', name: 'FPalletContent', width: 80, align: 'right' },
            { label: '标准容量', name: 'FPalletFactContent', width: 80, align: 'right' },
            { label: '凭证编号', name: 'FVoucherNo', width: 80, align: 'center' },
            { label: '备注', name: 'FDescription', width: 80, align: 'left' },
            { label: '供货单位', name: 'FProCompanyNO', width: 80, align: 'left' },

            { label: '供货单位名称', name: 'FProCompanyName', width: 120, align: 'left' },
            { label: '零件分类', name: 'FProductionTypeNO', width: 80, align: 'left', hidden: true },
            { label: '零件分类名称', name: 'FProductionTypeName', width: 80, align: 'left' },

            { label: '输入人员', name: 'FCreateBy', width: 80, align: 'left' },
            { label: '输入日期', name: 'FCreateDate', width: 80, align: 'center' },
            { label: '输入时间', name: 'FCreateTime', width: 80, align: 'center' }
            ],
            pager: "#gridPager2",
            sortname: 'FCurDate desc,FHappenCompanyNO desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            query($gridList);
        });
    }

    function btn_Add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/EnterWareHouse/WareHousePickInput"
        });
    }

    function btn_Delete() {
        var postData = $("#gridList1").jqGridRowValue().FRegisterID;
        $.deleteForm({
            url: "/WareHouse/EnterWareHouse/DeleteDJ_StoRegisterCC",
            param: { keyValue: postData },
            success: function () {
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function textChange() {
        $(".form").find(".decimal").keyup(function () {
            var $FactContent = 1;
            var $FQuantity = $("#txtFQuantity").val();
            var $FFactContent = $("#txtFFactContent").val();
            var $FPalletFactContent = $("#txtFPalletFactContent").val();
            if ($FFactContent != "") {
                $FactContent = Math.ceil($FQuantity / $FFactContent);
                $("#txtFContainerQuantity").val($FactContent);
            }
            if ($FPalletFactContent != "") {
                $("#txtFPalletQuantity").val(Math.ceil($FactContent / $FPalletFactContent));
            }
        });
    }

    function query(obj) {
       
        obj.jqGrid('setGridParam', {
            postData: { FHappenCompanyNO: $("#txtFHappenCompanyNO").val(), FProductionNO: $("#txtFProductionNOquery").val(), BeginFCurDate: $("#txtBeginFCurDate").val(), EndFCurDate: $("#txtEndFCurDate").val(), FVoucherNo: $("#txtqueryFVoucherNo").val() }
        }).trigger('reloadGrid');
    }

    function btn_Card() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/EnterWareHouse/WareHouseStorageCard"
        });
    }

    function btn_Excel() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/Export/WareHouseNoticeExcel"
        });
    }

    function btn_Print() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/Print/WareHouseNoticePrint"
        });
    }
</script>



